<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>完善当当购物车页面</title>
    <link type="text/css" rel="stylesheet" href="css/cartStyle.css" />

    <script type="text/javascript">

        /*ref=document.referrer;
        if (ref==""){
            document.write("<h1>能够对抗公开赛的四大金刚 5秒后跳转登录页面<h1/>");
            setTimeout("javascript:location.href='adv.html'","5000")
        }else {
            document.write("领奖");
        }*/


        document.write("host:"+window.location.host);
        document.write("hostname:"+window.location.hostname);
        document.write("href:"+window.location.href);

        //弹出窗口
        function open_adv() {
           // window.open("adv.html","11","200px")
        };
        function close_plan() {
            window.close();
        };
        function forword() {
            window.history.forward();
        }
        function reload() {
            location.reload();
        }
        function replacee() {
            location.replace("pp.html");
        }
    </script>
</head>
<body onload="open_adv();">

<div class="content">
    <div class="logo">
        <img src="images/dd_logo.jpg"><span onclick="close_plan()">关闭</span>
    </div>
    <div class="cartList">
        <ul>
            <li>¥<input type="text" name="price" value="21.90"></li>
            <li><input type="button" name="minus" value="-" onclick="jian(0)"><input type="text" name="amount" value="1"><input type="button" name="plus" onclick="add(0)" value="+"></li>
            <li id="price0" name="wpjg">¥21.90</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ul>
            <li>¥<input type="text" name="price" value="24.00"></li>
            <li><input type="button" name="minus" value="-" onclick="jian(1)"><input type="text" name="amount" value="1"><input type="button" name="plus" onclick="add(1)" value="+"></li>
            <li id="price1" name="wpjg">¥24.00</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ol>
            <li id="totalPrice">&nbsp;</li>
            <li><span onclick="jiesuan()">结 算</span></li>
        </ol>
        <div style="border: solid 1px red" id="info"></div>
    </div>
</div>

<script>

    function ygwyjg(index,one) {
        var wpjg =document.getElementsByName("wpjg");
        wpjg[index].innerHTML=one;
    }
    function jiesuan() {
        var prices=document.getElementsByName("price");
        var amounts=document.getElementsByName("amount");
        var sum=0;
        for (var i=0;i<prices.length;i++){
            one=parseFloat(prices[i].value)*parseInt(amounts[i].value);
            sum+=one;
            ygwyjg(i,one);
        }
        document.getElementById("totalPrice").innerHTML=("￥"+sum);

        var bai="白岩松 白说"+document.getElementsByClassName("cartList")[0].firstElementChild.lastElementChild.previousElementSibling.innerText;
        var dao="岛上书店"+document.getElementsByClassName("cartList")[0].firstElementChild.nextElementSibling.lastElementChild.previousElementSibling.innerText;
        document.getElementById("info").innerHTML=bai+"<br>"+dao;
    }
    function add(index) {
        var amounts=document.getElementsByName("amount");
        amounts[index].value=parseInt(amounts[index].value)+1;
        jiesuan();
    }
    function jian(index) {
        var amounts=document.getElementsByName("amount");
        ol=parseInt(amounts[index].value);
        if (ol>0){
            amounts[index].value=ol-1;
            jiesuan();
        }

    }



</script>

<a href="cyy.html">的分布格局</a>
<a href="#" onclick="replacee()">过的护肤 </a>
<input type="button" value="前进" onclick="forword()">
<input type="button" value="重新加载" onclick="reload()">
</body>
</html>